package com.app.server.impl;

import com.app.common.SystemConstant;
import com.app.mapper.FileMapper;
import com.app.model.FileModel;
import com.app.model.FileModel;
import com.app.server.FileService;
import com.app.vo.FileVo;
import com.app.vo.FileVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, FileModel> implements FileService {
    @Autowired
    private FileMapper fileMapper;

    @Override
    public FileVo getFileList(Integer page, Integer limit, Integer type) {
        Page<FileModel> page1 = new Page<>(page, limit);

        QueryWrapper<FileModel> qw = new QueryWrapper<>();
        if (type != null && type != 0) {
            qw.eq("file_type", type);
        }
        qw.orderByDesc("id");
        Page<FileModel> filePage = fileMapper.selectPage(page1, qw);
        List<FileModel> fileList = filePage.getRecords();
        long count = filePage.getTotal();
        FileVo FileVo = new FileVo();
        FileVo.setList(fileList);
        FileVo.setCount((int) count);
        return FileVo;
    }
}
